﻿using System.Collections.Generic;
using System.IO;
using DBCodeBuilder.Core.Models;
using Newtonsoft.Json;

namespace DBCodeBuilder.Core.Classes
{
    internal class ConfigSetup
    {
        public string Version { get; set; }
        public string Owner { get; set; }
        public string SelectedObjectType { get; set; }
        public List<TableModel> tables { get; set; }
        public string ModelNamespace { get; set; }
        public string MappingNamespace { get; set; }

        public static ConfigSetup LoadConfig(string filePath)
        {
            string config = File.ReadAllText(filePath);
            return JsonConvert.DeserializeObject<ConfigSetup>(config.IsBase64String() ? Utility.DecompressString(config) : config);
        }

        public void Save(string filePath)
        {
            File.WriteAllText(filePath, Utility.CompressString(JsonConvert.SerializeObject(this)));
        }
    }
}